unit udm;

interface

uses
  SysUtils, Classes, DBXpress, DB, SqlExpr, FMTBcd, DBClient, Provider,
  DBTables, ADODB;

type
  Tdm = class(TDataModule)
    sdsPallet: TSQLDataSet;
    dspPallet: TDataSetProvider;
    cdsPallet: TClientDataSet;
    cdsPalletDESCRICAO: TStringField;
    cdsPalletSTATUS: TStringField;
    cdsPalletPALLETID: TBCDField;
    dsPallet: TDataSource;
    sdsPalletPALLETID: TBCDField;
    sdsPalletDESCRICAO: TStringField;
    sdsPalletSTATUS: TStringField;                
    sdsEmpresa: TSQLDataSet;
    dspEmpresa: TDataSetProvider;
    cdsEmpresa: TClientDataSet;
    cdsEmpresaCLIENTE: TStringField;
    cdsEmpresaRAZAO_SOCIAL: TStringField;
    dsEmpresa: TDataSource;
    sdsUser: TSQLDataSet;
    cdsUser: TClientDataSet;
    dspUser: TDataSetProvider;
    dsUser: TDataSource;
    sdsUserUSU_LOGUSU: TStringField;
    sdsUserUSU_CODSUP: TStringField;
    sdsUserUSU_NOMUSU: TStringField;
    sdsUserUSU_NUMUSU: TStringField;
    sdsUserUSU_UCARGO: TStringField;
    sdsUserUSU_STATUS: TStringField;
    sdsUserUSU_KEYPAS: TStringField;
    sdsUserUSU_TIPUSU: TStringField;
    sdsUserUSU_LANBLQ: TBCDField;
    sdsUserUSU_ALTPAS: TBCDField;
    sdsUserUSU_DATPAS: TSQLTimeStampField;
    sdsUserUSU_DATEXP: TSQLTimeStampField;
    sdsUserUSU_E_MAIL: TStringField;
    sdsUserUSU_NUMTEL: TStringField;
    sdsUserUSU_NRAMAL: TStringField;
    sdsUserUSU_APELID: TStringField;
    sdsUserUSU_MAXSOL: TFMTBCDField;
    sdsUserUSU_MAXPED: TFMTBCDField;
    sdsUserUSU_TIPOPV: TBCDField;
    sdsUserUSU_BLQCOM: TStringField;
    sdsUserUSU_PVMETO: TFMTBCDField;
    cdsUserUSU_LOGUSU: TStringField;
    cdsUserUSU_CODSUP: TStringField;
    cdsUserUSU_NOMUSU: TStringField;
    cdsUserUSU_NUMUSU: TStringField;
    cdsUserUSU_UCARGO: TStringField;
    cdsUserUSU_STATUS: TStringField;
    cdsUserUSU_KEYPAS: TStringField;
    cdsUserUSU_TIPUSU: TStringField;
    cdsUserUSU_LANBLQ: TBCDField;
    cdsUserUSU_ALTPAS: TBCDField;
    cdsUserUSU_DATPAS: TSQLTimeStampField;
    cdsUserUSU_DATEXP: TSQLTimeStampField;
    cdsUserUSU_E_MAIL: TStringField;
    cdsUserUSU_NUMTEL: TStringField;
    cdsUserUSU_NRAMAL: TStringField;
    cdsUserUSU_APELID: TStringField;
    cdsUserUSU_MAXSOL: TFMTBCDField;
    cdsUserUSU_MAXPED: TFMTBCDField;
    cdsUserUSU_TIPOPV: TBCDField;
    cdsUserUSU_BLQCOM: TStringField;
    cdsUserUSU_PVMETO: TFMTBCDField;
    sdsPack: TSQLDataSet;
    dspPack: TDataSetProvider;
    cdsPack: TClientDataSet;
    sdsEmb: TSQLDataSet;
    dspEmb: TDataSetProvider;
    cdsEmb: TClientDataSet;
    cdsEmbPACKEMB_ID: TStringField;
    cdsEmbPACKEMB_DESC: TStringField;
    cdsEmbTPE_CODIGO: TBCDField;
    QPesq: TQuery;
    QPesqFANTASMA: TStringField;
    QPesqPRODUTO: TStringField;
    QPesqSEQ: TFloatField;
    QPesqDESCRICAO_CCUSTO: TStringField;
    QPesqTAREFA: TStringField;
    QPesqPROGRAMADO: TFloatField;
    QPesqPRODUZIDO: TFloatField;
    QPesqSALDO: TFloatField;
    QPesqSALDO_TERCEIRO: TFloatField;
    QPesqSALDO_IRBAS: TFloatField;
    QPesqCOD_OF: TStringField;
    QPesqINSTRUCAO: TMemoField;
    QPesqCCUSTO: TFloatField;
    QPesqDESCRICAO: TStringField;
    QPesqPROD: TStringField;
    sdsEtiqueta: TSQLDataSet;
    sdsEtiquetaETI_CODETI: TStringField;
    sdsEtiquetaETI_QTDENV: TFMTBCDField;
    sdsEtiquetaETI_CODPRO: TStringField;
    sdsEtiquetaETI_LOTE: TFMTBCDField;
    sdsEtiquetaDOF_CODIOF: TStringField;
    sdsEtiquetaDOF_CODIGO: TFMTBCDField;
    sdsEtiquetaETI_DATETI: TSQLTimeStampField;
    sdsEtiquetaPRO_DESCRI: TStringField;
    sdsEtiquetaPRO_DESCRI1: TStringField;
    sdsEtiquetaDOF_DATDOF: TSQLTimeStampField;
    sdsEtiquetaDOF_CODTUR: TBCDField;
    dspEtiqueta: TDataSetProvider;
    cdsEtiqueta: TClientDataSet;
    cdsEtiquetaETI_CODETI: TStringField;
    cdsEtiquetaETI_QTDENV: TFMTBCDField;
    cdsEtiquetaETI_CODPRO: TStringField;
    cdsEtiquetaETI_LOTE: TFMTBCDField;
    cdsEtiquetaDOF_CODIOF: TStringField;
    cdsEtiquetaDOF_CODIGO: TFMTBCDField;
    cdsEtiquetaETI_DATETI: TSQLTimeStampField;
    cdsEtiquetaPRO_DESCRI: TStringField;
    cdsEtiquetaPRO_DESCRI1: TStringField;
    cdsEtiquetaDOF_DATDOF: TSQLTimeStampField;
    dsEtiqueta: TDataSource;
    sdsBusca: TSQLDataSet;
    dspBusca: TDataSetProvider;
    cdsBusca: TClientDataSet;
    sProcLog: TSQLStoredProc;
    sdsUserUSU_EXILOG: TStringField;
    sdsUserPFU_CODFUN: TBCDField;
    cdsUserUSU_EXILOG: TStringField;
    cdsUserPFU_CODFUN: TBCDField;
    sProcRefugo: TSQLStoredProc;
    cdsEtiquetaDOF_CODTUR: TBCDField;
    SQLConnection1: TSQLConnection;
    spEtiq_NQTDE: TSQLStoredProc;
    sdsEtiquetaPRO_COMP03: TStringField;
    cdsEtiquetaPRO_COMP03: TStringField;
    sqlBusca: TSQLQuery;
    procedure DataModuleCreate(Sender: TObject);
    procedure SQLConnection1dAfterConnect(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
    user, funcao, empresa : string;
    PortaLpt: String;
    casasDecimais: Integer;
    function TraduzErro(p_MsgErro : String; var p_MsgTrad: String) : String;
  end;

var
  dbxconec: TStringList;
  dm: Tdm;

implementation

{$R *.dfm}

procedure Tdm.DataModuleCreate(Sender: TObject);
begin
  casasDecimais := 3;
  //ThousandSeparator := '.';
  //DecimalSeparator  := ',';
  SQLConnection1.Connected := False;

  SQLConnection1.LoadParamsFromIniFile('dbxconnections.ini');

  SQLConnection1.Params.Add( 'RowsetSize=20' );
  SQLConnection1.Params.Add( 'LocaleCode=0000' );
  //SQLConnection1.Params.Add( 'Oracle TransIsolation=ReadCommited' );
  //SQLConnection1.Params.Add( 'OS Authentication=False' );
  //SQLConnection1.Params.Add( 'Multiple Transaction=False' );
  SQLConnection1.Params.Add( 'Trim Char=False' );
  SQLConnection1.Connected := True;
  SQLConnection1.ExecuteDirect('ALTER SESSION SET ' +
                              'NLS_LANGUAGE = "BRAZILIAN PORTUGUESE" ' +
                              'NLS_TERRITORY = BRAZIL ' +
                              'NLS_DATE_FORMAT = ''DD/MM/YYYY'' ' +
                              'NLS_SORT = BINARY ' +
                              'NLS_NUMERIC_CHARACTERS = ''.,''');
  SQLConnection1.SQLConnection.SetOption(eConnBlobSize, LongInt(1048576));

  dbxconec := TStringList.Create;
  try
    dbxconec.LoadFromFile('dbxconnections.ini');
 //  empresa := dbxconec[9];
 //   empresa := copy(portaLpt,6,length(portaLpt));

    sqlBusca.Close;
    sqlBusca.SQL.Clear;
    sqlBusca.SQL.Add('SELECT PAR_EMPRES FROM F_PARAM');
    sqlBusca.Open;

    empresa := sqlBusca.Fields[0].asString ;

    portaLpt := dbxconec[9];
    portaLpt := copy(portaLpt,7,length(portaLpt));
  finally
    dbxconec.Free;
  end;
end;

procedure Tdm.SQLConnection1dAfterConnect(Sender: TObject);
begin
  SQLConnection1.ExecuteDirect('ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ' +
    QuotedStr('.,'));
end;

function Tdm.TraduzErro(p_MsgErro: String; var p_MsgTrad: String): String;
var sErro: string;
begin
  sErro := Copy( p_MsgErro, Pos('/***', p_MsgErro) + 4, Length(p_MsgErro) );
  sErro := Copy( sErro, 1, Pos('***/', sErro) - 1  );
  if (sErro = '') then
  begin
    sErro := Copy( p_MsgErro, 0, 9);
  end;
  Result := sErro;
end;

end.
